# Contributor: Ben Pye <ben@curlybracket.co.uk>
# Maintainer: Krassy Boykinov <kboykinov@teamcentrixx.com>
pkgname=libunwind
pkgver=1.8.1
pkgrel=0
pkgdesc="Portable and efficient C programming interface (API) to determine the call-chain of a program"
url="https://www.nongnu.org/libunwind/"
arch="all"
license="MIT"
options="!check" # v1.4.0 12 tests failing - https://github.com/libunwind/libunwind/issues/164
depends_dev="libucontext-dev"
makedepends_build="autoconf automake libtool"
makedepends_host="$depends_dev linux-headers xz-dev"
makedepends="$makedepends_build $makedepends_host"
subpackages="$pkgname-dbg $pkgname-static $pkgname-dev $pkgname-doc"
source="https://github.com/libunwind/libunwind/releases/download/v$pkgver/libunwind-$pkgver.tar.gz
	force-enable-man.patch
	fix-libunwind-pc-in.patch
	Remove-the-useless-endina.h-for-loongarch64.patch
	"

build() {
	# shellcheck disable=2046
	LDFLAGS="$LDFLAGS -lucontext" CFLAGS="$CFLAGS -fno-stack-protector" \
	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-cxx-exceptions \
		$(want_check || echo --disable-tests)
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

sha512sums="
aba7b578c1b8cbe78f05b64e154f3530525f8a34668b2a9f1ee6acb4b22c857befe34ad4e9e8cca99dbb66689d41bc72060a8f191bd8be232725d342809431b3  libunwind-1.8.1.tar.gz
2d210a2d8e960610e515d8cf9ebd388faa30a4f35613cae6a40a06e1ca1267540b974e96a9d94c02c465d47e114d3d3d6cbad72b4c1dbd0eb53d812970b1712d  force-enable-man.patch
ab5d44e9d3aaf32e3119fe79389e5dfcdc859c78cfda8400e54ee29fd1cdf04b99e2686caf18ab0b76ac94f861861d69a5cf740d46967af9c630095485523f1c  fix-libunwind-pc-in.patch
db8ab626920fa7fea5f0ff17e92909f0b293804eca61425dff53dd79a0f92b4db80941850fa144cfc9ecd2e1537b26fa8d62c56824ffea8e2790ed3930c8ff96  Remove-the-useless-endina.h-for-loongarch64.patch
"
